﻿using System;
using log4net;
using System.Diagnostics.Contracts;

namespace YasharEl.Infrastructure.Diagnostics.Logging.Log4Net
{
    public class Log4netLogger<T> : BaseLogger<T>
    {
        #region Fields

        private readonly ILog log4NetLogger;

        #endregion

        #region Constructors

        public Log4netLogger(ILog log4netLogger)
        {
            Contract.Requires<ArgumentNullException>(log4netLogger != null, "log4netLogger could not be null.");
            this.log4NetLogger = log4netLogger;
        }

        #endregion

        #region BaseLogger<T> Implementations

        public override bool IsDebugEnabled
        {
            get { return log4NetLogger.IsDebugEnabled; }
        }

        public override bool IsErrorEnabled
        {
            get { return log4NetLogger.IsErrorEnabled; }
        }

        public override bool IsFatalEnabled
        {
            get { return log4NetLogger.IsFatalEnabled; }
        }

        public override bool IsInfoEnabled
        {
            get { return log4NetLogger.IsInfoEnabled; }
        }

        public override bool IsWarnEnabled
        {
            get { return log4NetLogger.IsWarnEnabled; }
        }

        public override void Debug(string format, params object[] args)
        {
            log4NetLogger.DebugFormat(format, args);
        }

        public override void Debug(Exception exception, string format, params object[] args)
        {
            log4NetLogger.Debug(string.Format(format, args), exception);
        }

        public override void Error(string format, params object[] args)
        {
            log4NetLogger.ErrorFormat(format, args);
        }

        public override void Error(Exception exception, string format, params object[] args)
        {
            log4NetLogger.Error(string.Format(format, args), exception);
        }

        public override void Fatal(string format, params object[] args)
        {
            log4NetLogger.FatalFormat(format, args);
        }

        public override void Fatal(Exception exception, string format, params object[] args)
        {
            log4NetLogger.Fatal(string.Format(format, args), exception);
        }

        public override void Info(string format, params object[] args)
        {
            log4NetLogger.InfoFormat(format, args);
        }

        public override void Info(Exception exception, string format, params object[] args)
        {
            log4NetLogger.Info(string.Format(format, args), exception);
        }

        public override void Warn(string format, params object[] args)
        {
            log4NetLogger.WarnFormat(format, args);
        }

        public override void Warn(Exception exception, string format, params object[] args)
        {
            log4NetLogger.Warn(string.Format(format, args), exception);
        }

        #endregion
    }

    public class Log4netLogger : ILogger
    {
        #region Fields

        private readonly ILog log4NetLogger;

        #endregion

        #region Constructors

        public Log4netLogger(ILog log4netLogger)
        {
            Contract.Requires<ArgumentNullException>(log4netLogger != null, "log4netLogger could not be null.");
            this.log4NetLogger = log4netLogger;
        }

        #endregion

        #region ILogger Implementations

        public bool IsDebugEnabled
        {
            get { return log4NetLogger.IsDebugEnabled; }
        }

        public bool IsErrorEnabled
        {
            get { return log4NetLogger.IsErrorEnabled; }
        }

        public bool IsFatalEnabled
        {
            get { return log4NetLogger.IsFatalEnabled; }
        }

        public bool IsInfoEnabled
        {
            get { return log4NetLogger.IsInfoEnabled; }
        }

        public bool IsWarnEnabled
        {
            get { return log4NetLogger.IsWarnEnabled; }
        }

        public void Debug(string format, params object[] args)
        {
            log4NetLogger.DebugFormat(format, args);
        }

        public void Debug(Exception exception, string format, params object[] args)
        {
            log4NetLogger.Debug(string.Format(format, args), exception);
        }

        public void Error(string format, params object[] args)
        {
            log4NetLogger.ErrorFormat(format, args);
        }

        public void Error(Exception exception, string format, params object[] args)
        {
            log4NetLogger.Error(string.Format(format, args), exception);
        }

        public void Fatal(string format, params object[] args)
        {
            log4NetLogger.FatalFormat(format, args);
        }

        public void Fatal(Exception exception, string format, params object[] args)
        {
            log4NetLogger.Fatal(string.Format(format, args), exception);
        }

        public void Info(string format, params object[] args)
        {
            log4NetLogger.InfoFormat(format, args);
        }

        public void Info(Exception exception, string format, params object[] args)
        {
            log4NetLogger.Info(string.Format(format, args), exception);
        }

        public void Warn(string format, params object[] args)
        {
            log4NetLogger.WarnFormat(format, args);
        }

        public void Warn(Exception exception, string format, params object[] args)
        {
            log4NetLogger.Warn(string.Format(format, args), exception);
        }

        #endregion
    }
}
